package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.VehicleRentals;
import com.ruoyi.system.service.IVehicleRentalsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆租赁信息Controller
 *
 * @author ruoyi
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/system/rentals")
public class VehicleRentalsController extends BaseController
{
    @Autowired
    private IVehicleRentalsService vehicleRentalsService;

    /**
     * 查询车辆租赁信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:list')")
    @GetMapping("/list")
    public TableDataInfo list(VehicleRentals vehicleRentals)
    {
        startPage();
        List<VehicleRentals> list = vehicleRentalsService.selectVehicleRentalsList(vehicleRentals);
        return getDataTable(list);
    }

    /**
     * 导出车辆租赁信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:export')")
    @Log(title = "车辆租赁信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleRentals vehicleRentals)
    {
        List<VehicleRentals> list = vehicleRentalsService.selectVehicleRentalsList(vehicleRentals);
        ExcelUtil<VehicleRentals> util = new ExcelUtil<VehicleRentals>(VehicleRentals.class);
        util.exportExcel(response, list, "车辆租赁信息数据");
    }

    /**
     * 获取车辆租赁信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:query')")
    @GetMapping(value = "/{vehicleId}")
    public AjaxResult getInfo(@PathVariable("vehicleId") Long vehicleId)
    {
        return success(vehicleRentalsService.selectVehicleRentalsByVehicleId(vehicleId));
    }

    /**
     * 新增车辆租赁信息
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:add')")
    @Log(title = "车辆租赁信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleRentals vehicleRentals)
    {
        vehicleRentals.setVehicleStatus("0");
        vehicleRentals.setCreatedAt(new Date());
        vehicleRentals.setUpdatedAt(new Date());
        return toAjax(vehicleRentalsService.insertVehicleRentals(vehicleRentals));
    }

    /**
     * 修改车辆租赁信息
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:edit')")
    @Log(title = "车辆租赁信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleRentals vehicleRentals)
    {
        return toAjax(vehicleRentalsService.updateVehicleRentals(vehicleRentals));
    }

    /**
     * 删除车辆租赁信息
     */
    @PreAuthorize("@ss.hasPermi('system:rentals:remove')")
    @Log(title = "车辆租赁信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleIds)
    {
        return toAjax(vehicleRentalsService.deleteVehicleRentalsByVehicleIds(vehicleIds));
    }
}
